var ctx;


function setCtx(ctx) {
	this.ctx = ctx;
}


//验证标题不能为空
function checkTitle(){
	var title = $("#title").val();
	//解决ie9以下placeholder与value重复的问题
	if(title == $("#title").attr("placeholder")){
		title = "";
	}
	if(title == null || title == ""){
		layer.tips('名称不能为空!', '#title', {
		    tips: 3
		});
		return false;
	}else{
		return true;
	}
}

//验证排序不能为空
function checkSort(){
	var reg = /^[0-9]*[1-9][0-9]*$/;
	var sort = $("#sort").val();
	if(sort == null || sort == ""){
		layer.tips('排序不能为空!', '#sort', {
			tips: 3,
			time:1000
		});
		return false;
	}else if(!reg.test(sort)){
		layer.tips('请输入正整数!', '#sort', {
			tips: 3,
			time:1000
		});
		return false;
	}else{
		return true;
	}
}

//验证小区选择不能为空
function checkCell(){
	var cellId = $("#cellId").val();
	if(cellId == null || cellId == "") {
		layer.tips('小区不能为空!', '#cellId', {
			tips: 3,
			time:1000
		});
		return false;
	}else {
		return true;
	}
}

//保存或新增方法
function saveHelpManual() {
	var title = $('#title').val();
	var sort = $('#sort').val();
	var cellId = $('#cellId').val();
	if($('#helpId').val() != "" && $('#helpId').val() != undefined){
		helpId = $('#helpId').val();
	}else{
		helpId = 0;
	}
	var imageLogoUrl = $('#imageLogo').val();
	var pageType = $('#pageType').val();
	var container = ue.getContent();

	if(checkTitle() && checkSort() && checkCell()){
		var index1 = layer.load(1);
			$.ajax({
				type : "POST",
				url : ctx + "/helpManual/saveOrUpdateHelpManual",
				cache : false,
				dataType : 'json',
				data: {
					title : title,
					sort : sort,
					cellId : cellId,
					answer : container,
					helpId :helpId,
					logo : imageLogoUrl,
					pageType : pageType
				},
				success : function(result) {
					if (result.success) {
						layer.msg("操作成功",{
							icon: 1,
							time: 3000 //2秒关闭（如果不配置，默认是3秒）
						},function(){
							loadContent("/helpManual/helpManualList?pageType=" + pageType);
						});
					} else {
						layer.close(index1);
						layer.msg("操作失败",{
							icon: 2
						});
					}
				}
			});
	}

			
}

//返回上一页
function cancel(){
	loadContent("/helpManual/helpManualList?pageType=" + pageType);
}